package com.vincent.suchao.lcld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.RelativeLayout;

import com.vincent.suchao.adapter.NineMenuAdapter;
import com.vincent.suchao.entity.NineMenuItem;
import com.vincent.suchao.util.Util;

public class MainActivity extends Activity implements OnItemClickListener {
	GridView gv_menu;
	NineMenuAdapter nmAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		init();

		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);

		int screenWidth = dm.widthPixels;

		int screenHeight = dm.heightPixels;

		// System.out.println("screenWidth: " + screenWidth + ";screenHeight: "
		// + screenHeight);
		
//		new Thread(new Runnable() {
//			
//			@Override
//			public void run() {
//				String json = Util.test();
//				String json2 = Util.test2();
//				System.out.println("json: " + json);
//				try {
//					String result = Util.post(Util.NEWS_URL, json);
//					System.out.println(" result: " + result);
//					String result2 = Util.post(Util.NEWS_URL2, json2);
//					System.out.println(" result2: " + result2);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		}).start();
		
	}

	private void init() {
		Button	b_back = (Button)findViewById(R.id.b_back);
		b_back.setVisibility(View.GONE);
		gv_menu = (GridView) findViewById(R.id.gv_menu);
		nmAdapter = new NineMenuAdapter(this);
		gv_menu.setAdapter(nmAdapter);
		gv_menu.setOnItemClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

		RelativeLayout rl_inflate_menu = (RelativeLayout) arg1.findViewById(R.id.rl_inflate_menu);
		NineMenuItem menuItem = (NineMenuItem) rl_inflate_menu.getTag(R.id.rl_inflate_menu);
		Intent intent = new Intent();
		switch (menuItem.getResID()) {
		case R.drawable.menu_gsjj:
			intent.setClass(this, GSJJ_Activity.class);
			break;
		case R.drawable.menu_zxdt:
			intent.setClass(this, ZXDT_Activity.class);
			break;

		case R.drawable.menu_ywjs:
			intent.setClass(this, YWJS_Activity.class);
			break;
		case R.drawable.menu_cgal:
			intent.setClass(this, CGAL_Activity.class);
			break;
		case R.drawable.menu_tdjs:
			intent.setClass(this, TDJS_Activity.class);
			break;
		case R.drawable.menu_hzlc:
			intent.setClass(this, HZLC_Activity.class);
			break;
		case R.drawable.menu_lxwm:
			intent.setClass(this, LXWM_Activity.class);
			break;
		default:
			break;
		}

		startActivity(intent);

	}

}
